﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace GameEngine.GameStateManagment
{
    public class GameStateManagment
    {
        #region Variablen und Accessoren

        // 0 = LadeScreen zu Spielbeginn
        // 1 = Hauptmenü
        // 2 = LadeScreen für das Spiel
        // 3 = SinglePlayer (Spiel)
        // 4 = Pausemenü
        // 5 = GameOver
        private static Int32 _GameState;

        private static SpriteBatch _SpriteBatch;

        private static GameScreen[] _GameScreens;

        private static bool _EndGame;

        public static Int32 GameState
        {
            get { return _GameState; }
            set { _GameState = value; }
        }

        public static SpriteBatch SpriteBatch
        {
            get { return _SpriteBatch; }
            set { _SpriteBatch = value; }
        }

        public static GameScreen[] GameScreens
        {
            get { return _GameScreens; }
            set { _GameScreens = value; }
        }

        public static bool EndGame
        {
            get { return _EndGame; }
            set { _EndGame = value; }
        }

        #endregion

        public static void Init(SpriteBatch SpriteBatch)
        {
            _SpriteBatch = SpriteBatch;
            Init();
        }

        public static void Init()
        {
            // Setze GameScreen auf 0 damit zu Beginn
            // der LadeScreen sichtbar ist
            _GameState = 0;

            // Spiel nicht beenden
            _EndGame = false;

            // 0 = LadeScreen zu Spielbeginn
            // 1 = Hauptmenü
            // 2 = LadeScreen für das Spiel
            // 3 = SinglePlayer (Spiel)
            // 4 = Pausemenü
            // 5 = GameOver
            _GameScreens = new GameScreen[6];
            _GameScreens[0] = new LadeScreenBeginn();
            _GameScreens[1] = new Hauptmenue();
            _GameScreens[2] = new LadeScreenSpiel();
            _GameScreens[3] = new SinglePlayer();
            _GameScreens[4] = new Pausemenue();
            _GameScreens[5] = new GameOver();

            for (int i = 0; i < _GameScreens.Length; i++)
            {
                _GameScreens[i].Init();
            }
        }

        public static void LoadContent(ContentManager Content)
        {
            for (int i = 0; i < _GameScreens.Length; i++)
            {
                _GameScreens[i].LoadContent(Content);
            }
        }

        public static void Update()
        {
            switch (_GameState)
            {
                case 0:
                    {
                        // 0 = LadeScreen zu Spielbeginn
                        _GameScreens[0].Update();
                        break;
                    }
                case 1:
                    {
                        // 1 = Hauptemenü
                        _GameScreens[1].Update();
                        break;
                    }
                case 2:
                    {
                        // 2 = LadeScreen für das Spiel
                        _GameScreens[2].Update();
                        break;
                    }
                case 3:
                    {
                        // 3 = SinglePlayer (Spiel)
                        _GameScreens[3].Update();
                        break;
                    }
                case 4:
                    {
                        // 4 = Pausemenü
                        _GameScreens[4].Update();
                        break;
                    }
                case 5:
                    {
                        // 5 = GameOver
                        _GameScreens[5].Update();
                        break;
                    }
            }

        }

        public static void Draw()
        {
            switch (_GameState)
            {
                case 0:
                    {
                        // 0 = LadeScreen zu Spielbeginn
                        _GameScreens[0].Draw();
                        break;
                    }
                case 1:
                    {
                        // 1 = Hauptemenü
                        _GameScreens[1].Draw();
                        break;
                    }
                case 2:
                    {
                        // 2 = LadeScreen für das Spiel
                        _GameScreens[2].Draw();
                        break;
                    }
                case 3:
                    {
                        // 3 = SinglePlayer (Spiel)
                        _GameScreens[3].Draw();
                        break;
                    }
                case 4:
                    {
                        // 4 = Pausemenü
                        _GameScreens[4].Draw();
                        break;
                    }
                case 5:
                    {
                        // 5 = GameOver
                        _GameScreens[5].Draw();
                        break;
                    }
            }

        }

    }
}
